import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:flutter_note/note/base.dart';
import 'package:flutter_note/note/const.dart';
import 'package:flutter_note/note/page_book.dart';
import 'package:flutter_note/note/page_mark.dart';
import 'package:flutter_note/note/page_note.dart';
import 'package:flutter_note/note/page_setting.dart';

class HomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _HomePageState();
  }
}

class _HomePageState extends BaseState<HomePage> {
  var _pages = <Widget>[];
  int _currentPageIndex = 0;

  @override
  void initState() {
    super.initState();
    _initData();
  }

  @override
  void dispose() {
    super.dispose();
  }

  void _initData() async {
    _pages.add(NotePage());
    _pages.add(MarkPage());
    _pages.add(BookPage());
    _pages.add(SettingPage());
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: scaffoldkey,
      backgroundColor: color.bg_page,
      appBar: AppBar(
        title: Text('我的日记'),
        elevation: dim.x2,
      ),
      body: IndexedStack(
        //不重绘页面
        index: _currentPageIndex,
        children: _pages,
      ),
      bottomNavigationBar: BottomNavigationBar(
        fixedColor: color.green,
        items: <BottomNavigationBarItem>[
          buildBottomNavigationBarItem(Icons.view_list, "最新"),
          buildBottomNavigationBarItem(Icons.star, '关注'),
          buildBottomNavigationBarItem(Icons.view_module, '日记本'),
          buildBottomNavigationBarItem(Icons.settings, '设置'),
        ],
        //设置显示的模式
        type: BottomNavigationBarType.fixed,
        //设置当前的索引
        currentIndex: _currentPageIndex,
        //tabBottom的点击监听
        onTap: (index) {
          setState(() {
            _currentPageIndex = index;
          });
        },
      ),
    );
  }

  BottomNavigationBarItem buildBottomNavigationBarItem(
      IconData iconData, String title) {
    return BottomNavigationBarItem(icon: Icon(iconData), title: Text(title));
  }
}
